package com.matt.components.swagger2;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
//@Profile({"dev"})
public class Swagger2Config {

	@Bean
    public Docket createRestApiWeb() {
    	com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.matt.controller.web");

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("网页"))
                .groupName("网页")
                .select()
                .apis(selector1)
                .paths(PathSelectors.any()) //过滤的接口
                .build();
    }

    @Bean
    public Docket createRestApiGroup() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.matt.controller.group");

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("集团"))
                .groupName("集团")
                .select()
                .apis(selector1)
                .paths(PathSelectors.any()) //过滤的接口
                .build();
    }

    @Bean
    public Docket createRestApiMobile() {
        com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.matt.controller.pad");
        com.google.common.base.Predicate<RequestHandler> selector2 = RequestHandlerSelectors.basePackage("com.matt.controller.phone");

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("移动设备"))
                .groupName("移动设备")
                .select()
                .apis(Predicates.or(selector1,selector2))
                .paths(PathSelectors.any()) //过滤的接口
                .build();
    }

    @Bean
    public Docket createRestApiSys() {
        com.google.common.base.Predicate<RequestHandler> selector = RequestHandlerSelectors.basePackage("com.matt.controller.sys");

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("系统"))
                .groupName("系统")
                .select()
                .apis(selector)
                .paths(PathSelectors.any()) //过滤的接口
                .build();
    }
    @Bean
    public Docket createRestApiEvaluate() {
        com.google.common.base.Predicate<RequestHandler> selector = RequestHandlerSelectors.basePackage("com.tuo51.evaluate");
        Docket ret = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("测评"))
                .select()
                .apis(selector)
                .paths(PathSelectors.any())
                .build()
                .groupName("测评");
        return ret;
    }

    @Bean
    public Docket createRestApi() {
        com.google.common.base.Predicate<RequestHandler> selector = RequestHandlerSelectors.basePackage("com.dotflat");
        Docket ret = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo("通用Rest风格API"))
                .select()
                .apis(selector)
                .paths(PathSelectors.any())
                .build()
                .groupName("通用Rest风格API");
        return ret;
    }

    private ApiInfo apiInfo(String name) {
        return new ApiInfoBuilder()
                .title("教务系统接口 - " + name) //大标题
                .description("")
                .termsOfServiceUrl("http://dotflat.cn/")
                .contact(new Contact("Ron","http://sigarron.dev", "luoying@tuo51.com"))
                .version("1.0")
                .build();
    }

}